using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Viettel.VOFFICE.DAO.Models.Mapping
{
    public class DocumentBookMap : EntityTypeConfiguration<DocumentBook>
    {
        public DocumentBookMap()
        {
            // Primary Key
            this.HasKey(t => new { t.BookId, t.DocId });

            // Properties
            this.Property(t => t.BookId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.DocId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Code)
                .HasMaxLength(30);

            // Table & Column Mappings
            this.ToTable("DocumentBook");
            this.Property(t => t.BookId).HasColumnName("BookId");
            this.Property(t => t.DocId).HasColumnName("DocId");
            this.Property(t => t.BookNumber).HasColumnName("BookNumber");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.BookType).HasColumnName("BookType");
            this.Property(t => t.CreatedAt).HasColumnName("CreatedAt");
            this.Property(t => t.UpdatedAt).HasColumnName("UpdatedAt");
            this.Property(t => t.CreatorId).HasColumnName("CreatorId");

            // Relationships
            this.HasRequired(t => t.Book)
                .WithMany(t => t.DocumentBooks)
                .HasForeignKey(d => d.BookId);

        }
    }
}
